<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    let head5 = {
        value: 4,
        next: null
    }
    let head4 = {
        value: 4,
        next: null
    }
    let head3 = {
        value: 3,
        next: null
    }
    let head2 = {
        value: 2,
        next: null
    }
    let head = {
        value: 1,
        next: null
    }
    head.next = head2
    head2.next = head3
    head3.next = head4
    head4.next = head

    function fn(head) {
        let slow = head
        let fast = head.next
        //快指针多走两步 如果不是环形链表总会等于null返回false
        //如果是环形链表 会走到同一个对象
        while (slow !== fast) {
            if (!fast.next || !fast.next.next) {
                return false
            }
            slow = slow.next
            fast = fast.next.next
        }
        return true
    }
    console.log(fn(head));
    

</script>

</html>